package com.efeichong.project.controller;

import com.efeichong.common.domain.ResponseData;
import com.efeichong.project.domain.vo.DeptUserVo;
import com.efeichong.project.domain.vo.SysDeptVo;
import com.efeichong.project.service.SysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author
 * @date 2020/12/03
 * @description 部门表
 */
@Api(tags = "部门表 接口", value = "部门表接口")
@RestController
@RequestMapping("/sysDept")
@RequiredArgsConstructor
public class SysDeptController {

    private final SysDeptService sysDeptService;

    @ApiOperation(value = "部门表详细")
    @GetMapping(value = "/getInfo")
    public ResponseData<SysDeptVo> getInfo(@RequestParam("id") Long id) {
        return new ResponseData(sysDeptService.getInfo(id));
    }

    @ApiOperation(value = "部门列表查询")
    @GetMapping("/list")
    public ResponseData<SysDeptVo> list(SysDeptVo sysDeptVo) {
        return new ResponseData(sysDeptService.list(sysDeptVo));
    }

    @ApiOperation(value = "部门列表查询")
    @GetMapping("/queryDeptUser")
    public ResponseData<DeptUserVo> queryDeptUser(@RequestParam(value = "deptId", required = false) Long deptId) {
        return new ResponseData(sysDeptService.queryDeptUser(deptId));
    }

    @ApiOperation(value = "部门表新增")
    @PostMapping("insert")
    public ResponseData insert(@RequestBody SysDeptVo sysDeptVo) {
        sysDeptService.insertSysDept(sysDeptVo);
        return new ResponseData();
    }

    @ApiOperation(value = "部门表编辑")
    @PostMapping("update")
    public ResponseData update(@RequestBody SysDeptVo sysDeptVo) {
        sysDeptService.updateSysDept(sysDeptVo);
        return new ResponseData();
    }

    @ApiOperation(value = "部门表批量删除")
    @GetMapping("/deleteByIds")
    public ResponseData deleteSysDeptByIds(@RequestParam("ids") List<Long> ids) {
        sysDeptService.deleteByIds(ids);
        return new ResponseData();
    }

    @ApiOperation(value = "部门表删除")
    @GetMapping("/deleteById")
    public ResponseData deleteSysDeptById(@RequestParam("id") Long id) {
        sysDeptService.deleteById(id);
        return new ResponseData();
    }
}
